<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
	/**
	 功能名称:添加年度功能
	 @author:
	 **/
%>
<%
String path = request.getContextPath();
%>
<html>
  <head>
  <title>添加年度</title>
  <link href="<%=path %>/css/index_css.css" rel="stylesheet" type="text/css" />
  <script src="<%=path%>/dwr/engine.js"></script>
  <script src="<%=path%>/dwr/util.js"></script>
  <script src="<%=path%>/dwr/interface/shiyueDwr.js"></script>
  <script language="javascript" src="<%=path %>/js/syAjax.js"></script>
  <script type="text/javascript">
  	String.prototype.len=function(){		
	    var len = 0;
	    for (var i = 0; i < this.length; i++) {      
	        if (this.charCodeAt(i) > 255 || this.charCodeAt(i)<0) len += 2; else len ++;      
	    }      
		return len;
	}
     function getSchoolTermCallBack(schoolTerm) {
     if(!schoolTerm){
        alert("该年度存在，请确保年度唯一！");
        document.getElementById("yearValue").select();
     }
     } 
       
     function isSchoolTermValueExsit(){
     var value=document.getElementById("yearValue").value;
     shiyueDwr.isYearValueExsit(value,getSchoolTermCallBack);
     }
        
      function doAdd(){
	  var yearName=document.getElementById("yearName");
	  var yearValue=document.getElementById("yearValue");
	  if(yearName.value==""){
	    alert("年度不能为空！");
	    yearName.focus();
	    return;
	  }
	  if(yearValue.value==""){
	    alert("年度不能为空！");
	    yearValue.focus();
	    return;
	  }else{
	    if(!validateYear(yearValue)){
	    	yearValue.focus();
	    	return;
	    }
	  }
	  syAjax.request("post","saveYearyearAndSchoolTermAction.action","year.name="+yearName.value+"&year.yearValue="+yearValue.value,{success:initSuccessResult,fail:onFail,type:'plain'});
	}
	
	function initSuccessResult(response){
	  window.returnValue=response;
	  window.close();
	}
	
	//验证年度
	function validateYear(obj){
			var re = /^\d{4}-\d{4}$/;
            if(obj.value.length!=0 && re.test(obj.value)){ 
            isSchoolTermValueExsit();
            	return true;         
           }else{
                alert("你输入的年度格式不符合要求！");
                return false;
           }
    }
	</script>
  </head>
  <body bgcolor="#ECE9D8">
  <form action="" method="post">
    <table width="450" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td height="25" align="left" valign="bottom" bgcolor="#ECE9D8" class="f_8">&nbsp;&nbsp;&nbsp;&nbsp;注：<span class="f_11">*</span>为必填项</td>
  </tr>
  <tr>
    <td height="12" align="center" valign="middle" bgcolor="#ECE9D8"><table width="95%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td height="1" bgcolor="#ABA899"></td>
      </tr>
      <tr>
        <td height="1" bgcolor="#FFFFFF"></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td height="25" align="center" valign="top" bgcolor="#ECE9D8"><table width="95%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="25%" height="30" align="right" class="f_6"><span class="f_11">* </span>年度名称：</td>
        <td width="75%" align="left"><input type="text" maxlength="25" name="year.name" id="yearName"/></td>
      </tr>
      <tr>
        <td height="30" align="right" class="f_6"><span class="f_11">*</span> 年度：</td>
        <td align="left">
        <input type="text" name="year.yearValue" onblur="validateYear(this);" id="yearValue"/>
        </td>
      </tr>
      <tr>
        <td height="20" align="right" class="f_6">&nbsp;</td>
        <td align="left" valign="top" class="f_2">年度格式参照：2012-2013</td>
      </tr>
 
 
     
    </table></td>
  </tr>
  <tr>
    <td height="25" align="center" valign="middle" bgcolor="#ECE9D8"><table width="95%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td height="1" bgcolor="#ABA899"></td>
      </tr>
      <tr>
        <td height="1" bgcolor="#FFFFFF"></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td height="55" align="center" valign="middle" bgcolor="#ECE9D8"><input type="button" value="提 交" onclick="doAdd();" /></td>
  </tr>
</table>
</form>
  </body>
</html>
